#ifndef PHYSICALCONNECTOR_HPP
#define PHYSICALCONNECTOR_HPP

#include "DataTypes.h"
#include "message.h"
#include "serialportconnector.hpp"
#include "MessageParser.hpp"
#include "msgbuffer.h"

namespace Connectors{




class PhysicalConnector
{

    PhysicalConnector();

public:
    PhysicalConnector(SerialPortConnector* serialConnector, const PartiesAddresses& parties, const Message& pingPongMsg);
    void startCommunication();
    void stopCommunication();
    Message send(const Message& msgToSend);
    std::vector<Message> send(const Data& payload);
    // class made to send 55 55, nad wait for response which is 55 55 and two keywords,
    //than it recends logical inversion of second keyword, and receives logical inversion of phisical address of server
    /*
    Request: 55 55
    Answer:  55 55 D3 B0 (D3 = iso 14230?)

    Request: 4F       (~b0 = 4f)
    Answer:  4F A7    (~a7 = 58) 58 is ecu's address

    */
    char getRemoteAddr(){return m_addresses.remoteParty;}
    void setRemoteAddr(char addr){m_addresses.remoteParty = addr;}
    char getLocalAddr(){return m_addresses.localParty;}
    void setLocalAddr(char addr);
    AddressType getRemoteAddrType();
    void setRemoteAddrType(AddressType addrTp);
private:
    void pingPong();
    PartiesAddresses m_addresses;
    ConnectionState m_connState;
    SerialPortConnector* m_connector;
    Message m_ping;
    MsgBuffer m_buff;
};
}
#endif // PHYSICALCONNECTOR_HPP
